package com.sec.android.app.myfiles.facade.cmd;

import android.widget.Toast;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment.ActionModeType;
import com.sec.android.app.myfiles.navigation.NavigationManager;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;

import org.puremvc.java.multicore.interfaces.INotification;
import org.puremvc.java.multicore.patterns.command.SimpleCommand;

public class ToSelectModeCmd extends SimpleCommand {

    public enum SelectModeType {
        EDIT_MODE, SELECT_MODE
    }

    @Override
    public void execute(INotification notification) {
        Object[] params = (Object[]) notification.getBody();

        AbsMyFilesFragment fragment = (AbsMyFilesFragment) params[0];
        AbsListViewImp listViewImp = (AbsListViewImp) params[1];
        int selectedIndex = (Integer) params[2];
        SelectModeType selectType = (SelectModeType) params[3];

        if (NavigationManager.isPossibleToActionMode()) {
            switch (selectType) {
                case EDIT_MODE:
                    fragment.setActionMode(ActionModeType.EDIT_FILE_FOLDER_OPERATION);
                    break;
                case SELECT_MODE:
                    fragment.setActionMode(ActionModeType.SELECT_FILE_FOLDER_OPERATION);

                    if (listViewImp != null && selectedIndex >= 0) {
                        listViewImp.clearChoices();
                        listViewImp.setItemChecked(selectedIndex, true);
                        fragment.updateActionBarMenu();
                    }
                    break;
            }
        } else if (SelectModeType.EDIT_MODE.equals(selectType)) {
            Toast.makeText(fragment.getContext(), R.string.another_process_is_already_in_progress, Toast.LENGTH_LONG).show();
        } else if (SelectModeType.SELECT_MODE.equals(selectType)) {
            Toast.makeText(fragment.getContext(), R.string.cant_perform_action, Toast.LENGTH_LONG).show();
        }
    }
}
